import 'package:flutter/material.dart';

class Animated1Page extends StatefulWidget {

  const Animated1Page({super.key});

  @override
  State<Animated1Page> createState() => _Animated1PageState();

}

class _Animated1PageState extends State<Animated1Page> with SingleTickerProviderStateMixin{

  late AnimationController _controller;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _controller = AnimationController(
      vsync: this,
      duration: Duration(seconds: 1),//持续时间
    )..repeat();
  }

  @override
  void dispose() {
    // TODO: implement dispose
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      floatingActionButton: FloatingActionButton(
        onPressed: (){
          _controller.reset();
        },
        child: Icon(Icons.add),
      ),
      body: Center(
        child: Column(
          children: [
            SizedBox(height: 40,),
            // 旋转动画
            RotationTransition(turns: _controller, child: FlutterLogo(size: 120,),),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: [
                ElevatedButton(onPressed: (){
                  _controller.reset();
                }, child: Text("reset")),
                ElevatedButton(onPressed: (){
                  _controller.repeat();
                }, child: Text("repeat")),
                ElevatedButton(onPressed: (){
                  _controller.stop();
                }, child: Text("stop")),
                ElevatedButton(onPressed: (){
                  _controller.reverse();
                }, child: Text("reverse")),
                ElevatedButton(onPressed: (){
                  _controller.forward();
                }, child: Text("forward")),
              ],
            )
          ]
        ),
      ),
    );
  }
}
